﻿Imports System.IO

Public Class Form1
    Private OldText As String = String.Empty
    Private OldPosition As Integer = 0

    Private DefaultValueIsZero As Boolean = True
    Private SetDefault As Boolean = False

    Dim attributesAdded As Boolean = False
    Dim addedLooks As Boolean = False



    Private Sub TextBox3_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox3.KeyDown

        OldText = TextBox3.Text
        OldPosition = TextBox3.SelectionStart()
        SetDefault = False
        If OldText.Length = 1 Then
            If (OldPosition = 1 AndAlso e.KeyCode = Keys.Back) OrElse (OldPosition = 0 AndAlso e.KeyCode = Keys.Delete) Then
                If DefaultValueIsZero Then
                    OldText = ""
                    OldPosition = 1
                    SetDefault = True
                Else
                    OldText = ""
                    OldPosition = 0
                End If
            End If
        End If

    End Sub

    Private Sub TextBox3_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged

        Dim d As Integer = 0
        If Not Integer.TryParse(TextBox3.Text, d) Then
            TextBox3.Text = OldText
            TextBox3.SelectionStart = OldPosition
            TextBox3.SelectionLength = 0
        End If



    End Sub
    Private Sub TextBox4_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox4.KeyDown

        OldText = TextBox4.Text
        OldPosition = TextBox4.SelectionStart()
        SetDefault = False
        If OldText.Length = 1 Then
            If (OldPosition = 1 AndAlso e.KeyCode = Keys.Back) OrElse (OldPosition = 0 AndAlso e.KeyCode = Keys.Delete) Then
                If DefaultValueIsZero Then
                    OldText = ""
                    OldPosition = 1
                    SetDefault = True
                Else
                    OldText = ""
                    OldPosition = 0
                End If
            End If
        End If

    End Sub

    Private Sub TextBox4_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox4.TextChanged

        Dim d As Integer = 0
        If Not Integer.TryParse(TextBox4.Text, d) Then
            TextBox4.Text = OldText
            TextBox4.SelectionStart = OldPosition
            TextBox4.SelectionLength = 0
        End If



    End Sub
    Private Sub TextBox5_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox5.KeyDown

        OldText = TextBox5.Text
        OldPosition = TextBox5.SelectionStart()
        SetDefault = False
        If OldText.Length = 1 Then
            If (OldPosition = 1 AndAlso e.KeyCode = Keys.Back) OrElse (OldPosition = 0 AndAlso e.KeyCode = Keys.Delete) Then
                If DefaultValueIsZero Then
                    OldText = ""
                    OldPosition = 1
                    SetDefault = True
                Else
                    OldText = ""
                    OldPosition = 0
                End If
            End If
        End If

    End Sub

    Private Sub TextBox5_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox5.TextChanged

        Dim d As Integer = 0
        If Not Integer.TryParse(TextBox5.Text, d) Then
            TextBox5.Text = OldText
            TextBox5.SelectionStart = OldPosition
            TextBox5.SelectionLength = 0
        End If



    End Sub


    Private Sub TextBox6_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox6.KeyDown

        OldText = TextBox6.Text
        OldPosition = TextBox6.SelectionStart()
        SetDefault = False
        If OldText.Length = 1 Then
            If (OldPosition = 1 AndAlso e.KeyCode = Keys.Back) OrElse (OldPosition = 0 AndAlso e.KeyCode = Keys.Delete) Then
                If DefaultValueIsZero Then
                    OldText = ""
                    OldPosition = 1
                    SetDefault = True
                Else
                    OldText = ""
                    OldPosition = 0
                End If
            End If
        End If

    End Sub

    Private Sub TextBox6_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox6.TextChanged

        Dim d As Integer = 0
        If Not Integer.TryParse(TextBox6.Text, d) Then
            TextBox6.Text = OldText
            TextBox6.SelectionStart = OldPosition
            TextBox6.SelectionLength = 0
        End If

    End Sub

    Private Sub TextBox7_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox7.KeyDown

        OldText = TextBox7.Text
        OldPosition = TextBox7.SelectionStart()
        SetDefault = False
        If OldText.Length = 1 Then
            If (OldPosition = 1 AndAlso e.KeyCode = Keys.Back) OrElse (OldPosition = 0 AndAlso e.KeyCode = Keys.Delete) Then
                If DefaultValueIsZero Then
                    OldText = ""
                    OldPosition = 1
                    SetDefault = True
                Else
                    OldText = ""
                    OldPosition = 0
                End If
            End If
        End If

    End Sub

    Private Sub TextBox7_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox7.TextChanged

        Dim d As Integer = 0
        If Not Integer.TryParse(TextBox7.Text, d) Then
            TextBox7.Text = OldText
            TextBox7.SelectionStart = OldPosition
            TextBox7.SelectionLength = 0
        End If

    End Sub

    Private Sub TextBox8_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox8.KeyDown

        OldText = TextBox8.Text
        OldPosition = TextBox8.SelectionStart()
        SetDefault = False
        If OldText.Length = 1 Then
            If (OldPosition = 1 AndAlso e.KeyCode = Keys.Back) OrElse (OldPosition = 0 AndAlso e.KeyCode = Keys.Delete) Then
                If DefaultValueIsZero Then
                    OldText = ""
                    OldPosition = 1
                    SetDefault = True
                Else
                    OldText = ""
                    OldPosition = 0
                End If
            End If
        End If

    End Sub

    Private Sub TextBox8_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox8.TextChanged

        Dim d As Integer = 0
        If Not Integer.TryParse(TextBox8.Text, d) Then
            TextBox8.Text = OldText
            TextBox8.SelectionStart = OldPosition
            TextBox8.SelectionLength = 0
        End If

    End Sub

    Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs)
        System.Diagnostics.Process.Start("http://otland.net/forum.php")
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        RichTextBox1.Text = "<?xml version=""1.0"" encoding=""UTF-8""?>" & _
         vbNewLine & "<!-- Created using Nikolas' NPC XML File creating software-->"
        Label11.Text = "Welcome!"
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Close()
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        If attributesAdded = False And addedLooks = False Then
        End If
        If attributesAdded = False Then

            If TextBox1.Text <> "" And TextBox2.Text <> "" Then
                If CheckBox1.Checked = True And CheckBox2.Checked = True Then
                    RichTextBox1.Text = RichTextBox1.Text & vbNewLine & _
                    "<npc name=""" & TextBox1.Text & """" & vbNewLine & "script=""data/npc/scripts/" & _
                    TextBox2.Text & ".lua"" """ & "autowalk=""1"" changefloor=""1"" access= ""5""/>"
                    attributesAdded = True

                ElseIf CheckBox1.Checked = True And CheckBox2.Checked = False Then
                    RichTextBox1.Text = RichTextBox1.Text & vbNewLine & _
                    "<npc name=""" & TextBox1.Text & """" & vbNewLine & "script=""data/npc/scripts/" & _
                    TextBox2.Text & ".lua"" """ & "autowalk=""1"" changefloor=""0"" access= ""5""/>"
                    attributesAdded = True

                ElseIf CheckBox1.Checked = False And CheckBox2.Checked = True Then
                    RichTextBox1.Text = RichTextBox1.Text & vbNewLine & _
                    "<npc name=""" & TextBox1.Text & """" & vbNewLine & "script=""data/npc/scripts/" & _
                    TextBox2.Text & ".lua"" """ & "autowalk=""0"" changefloor=""1"" access= ""5""/>"
                    attributesAdded = True

                ElseIf CheckBox1.Checked = False And CheckBox2.Checked = False Then
                    RichTextBox1.Text = RichTextBox1.Text & vbNewLine & _
                    "<npc name=""" & TextBox1.Text & """" & vbNewLine & "script=""data/npc/scripts/" & _
                    TextBox2.Text & ".lua"" ""autowalk = ""0"" changefloor=""0"" access= ""5""/>"
                    attributesAdded = True

                End If
                Label11.Text = "Attributes added successfully."
            Else
                MsgBox("Error! NPC Name and Script Text Boxes can not be empty.", MsgBoxStyle.Critical, "Failure!")
                Label11.Text = "Illegal action."
            End If
        Else
            MsgBox("NPC Attributes already added." & vbNewLine & _
                   "You can't add the NPC's attributes twice.", MsgBoxStyle.Critical, "Failure!")
            Label11.Text = "Illegal action."
        End If

    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        Dim numberOfAddon As Integer

        If RadioButton1.Checked = True Then
            numberOfAddon = 0
        ElseIf RadioButton2.Checked = True Then
            numberOfAddon = 1
        ElseIf RadioButton3.Checked = True Then
            numberOfAddon = 2
        ElseIf RadioButton4.Checked = True Then
            numberOfAddon = 3
        End If

        If TextBox3.Text <> "" And TextBox4.Text <> "" And TextBox5.Text <> "" And TextBox6.Text <> "" _
        And TextBox7.Text <> "" And TextBox8.Text <> "" Then
            If addedLooks = False And attributesAdded = True Then
                RichTextBox1.Text = RichTextBox1.Text & vbNewLine & _
                "<health now=""150"" max=""150""/>" & vbNewLine & _
                "<look type=""" & TextBox3.Text & """ head=""" & TextBox4.Text & _
                """ body=""" & TextBox5.Text & """ legs=""" & TextBox6.Text & """ feet=""" & TextBox7.Text & _
                """ corpse=""" & TextBox8.Text & """ addons = """ & numberOfAddon _
                 & """/>" & vbNewLine & "<parameters>" & vbNewLine & "</parameters>" & vbNewLine & "</npc>"

                addedLooks = True
                Label11.Text = "NPC Look added successfully."
            ElseIf addedLooks = True And attributesAdded = True Then
                MsgBox("NPC Looks have already been added." & vbNewLine & _
                       "You can't add the NPC's look options twice.", MsgBoxStyle.Critical, "Failure!")
                If Label11.Text <> "" Then
                    Label11.Text = "Illegal action."
                End If
            ElseIf addedLooks = False And attributesAdded = False Then
                MsgBox("You must add the NPC's attributes first.", MsgBoxStyle.Critical, "Failure!")
                If Label11.Text <> "" Then
                    Label11.Text = "Illegal action."
                End If

            End If

        Else
            MsgBox("One of the look boxes is empty." & vbNewLine & "You must fill every text box.", _
                  MsgBoxStyle.Critical, "Failure!")
            If Label11.Text <> "" Then
                Label11.Text = "Illegal action."
            End If

        End If

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim newFileDir As String = Application.StartupPath & "/NPCs/" & TextBox1.Text & ".xml"
        Dim newFileStream As FileStream

        If Directory.Exists(Application.StartupPath & "/NPCs") = False Then
            If MessageBox.Show("NPCs Folder does not exist.Would you like to create it?", "Information", _
                           MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
                Directory.CreateDirectory(Application.StartupPath & "/NPCs")
            Else
                Exit Sub
            End If

        Else

            If attributesAdded = True And addedLooks = True Then
                newFileStream = New FileStream(newFileDir, FileMode.Create, FileAccess.ReadWrite, FileShare.None)
                Dim newFileWriter As New StreamWriter(newFileStream)

                newFileWriter.Write(RichTextBox1.Text)
                newFileWriter.Close()

            Else
                MsgBox("Error! NPC has not been created yet." & vbNewLine & _
                       "Add the NPC's Attributes and Look options in order to be able to save successfully.", _
                        MsgBoxStyle.Critical, "Failure!")
            End If
        End If


    End Sub


    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Form2.Show()
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        If attributesAdded = True And addedLooks = True Then
            Dim inputBoxMessage As String = ("Enter the greeting parameter's text." & vbNewLine & _
             "Example:" & vbNewLine & """Hello |PLAYERNAME| ,how are you today?""" & _
             vbNewLine & "Note: |PLAYERNAME| will be replaced with " & _
             "the player's name in game.")
            Dim greetParam As String = InputBox(inputBoxMessage, "Enter greeting text")

            RichTextBox1.Text = Replace(RichTextBox1.Text, "</parameters>", "<parameter key=""message_greet"" value=""" & _
                    greetParam & """/>" & vbNewLine & "</parameters>")
            Label11.Text = "Greeting param added successfully."
        Else
            MsgBox("NPC Attributes and Look options must have been added before proceeding with parameters.", _
                    MsgBoxStyle.Critical, "Failure!")
            Label11.Text = "Illegal Action."
        End If
    End Sub

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        If attributesAdded = True And addedLooks = True Then
            Dim inputBoxMessage As String = ("Enter the farewell parameter's text." & vbNewLine & _
                        "Example:" & vbNewLine & """Good bye, |PLAYERNAME|""" & vbNewLine & _
                        "Note: |PLAYERNAME| will be replaced with the player's name in game.")
            Dim farewellParam As String = InputBox(inputBoxMessage, "Enter farewell text")

            RichTextBox1.Text = Replace(RichTextBox1.Text, "</parameters>", "<parameter key=""message_farewell""" & _
                " value=""" & farewellParam & """/>" & vbNewLine & "</parameters>")
            Label11.Text = "Farewell param added successfully."
        Else
            MsgBox("NPC Attributes and Look options must have been added before proceeding with parameters.", _
                    MsgBoxStyle.Critical, "Failure!")
            Label11.Text = "Illegal Action."
        End If
    End Sub


    Private Sub CheckBox3_CheckStateChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox3.CheckStateChanged
        If attributesAdded = True And addedLooks = True = True Then
            Button9.Enabled = True
            RichTextBox1.Text = Replace(RichTextBox1.Text, "</parameters>", "<parameter key=""module_shop"" value=""1""/>" & vbNewLine _
                                        & "</parameters>")
            Label11.Text = "Shop module added successfully."
        Else
            Label11.Text = "You must the NPC's Attributes and outfit options before proceeding."
            CheckBox3.Checked = False
        End If
    End Sub

    Private Sub CheckBox4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox4.CheckedChanged
        If attributesAdded = True And addedLooks = True = True Then
            Dim needMoreMoney As String = InputBox("Enter the text that the NPC will reply with if the player does not have enough money to buy something.", "Enter Text")
            RichTextBox1.Text = Replace(RichTextBox1.Text, "</parameters>", "<parameter key=""message_needmoremoney"" value=""" & needMoreMoney & """/>" & vbNewLine _
                                        & "</parameters>")
            Label11.Text = "No-money reply added successfully."
        Else
            Label11.Text = "You must the NPC's Attributes and outfit options before proceeding."
            CheckBox4.Checked = False
        End If
    End Sub

    Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
        If addedLooks = True And attributesAdded = True Then

            If ComboBox1.Text = "MESSAGE_BUY" Then
                MsgBox("Examples of this parameter:" & vbNewLine & _
                       """Would you like to buy |ITEMCOUNT| |ITEMNAME| for |TOTALCOST| gold coins?""", MsgBoxStyle.Information, _
                "Parameter usage.")

                Dim buyMessage As String = InputBox("Enter a message that the NPC will reply with when the player buys an item.", "Enter Text")
                RichTextBox1.Text = Replace(RichTextBox1.Text, "</parameters>", "<parameter key=""MESSAGE_BUY"" value=""" & _
                            buyMessage & """/>" & vbNewLine & "</parameters>")
                Label11.Text = "MESSAGE_BUY added successfully."


            ElseIf ComboBox1.Text = "MESSAGE_SELL" Then
                MsgBox("Examples of this parameter:" & vbNewLine & _
                       """Would you like to sell |ITEMCOUNT| |ITEMNAME| for |TOTALCOST| gold coins?""", MsgBoxStyle.Information, _
                "Parameter usage.")

                Dim sellMessage As String = InputBox("Enter a message that the NPC will reply with when the player sells an item.", "Enter Text")
                RichTextBox1.Text = Replace(RichTextBox1.Text, "</parameters>", "<parameter key=""MESSAGE_SELL"" value=""" & _
                            sellMessage & """/>" & vbNewLine & "</parameters>")
                Label11.Text = "MESSAGE_SELL added successfully."


            ElseIf ComboBox1.Text = "MESSAGE_ONBUY" Then
                MsgBox("Examples of this parameter:" & vbNewLine & _
                       """Thank you for buying |ITEMCOUNT| |ITEMNAME| for |TOTALCOST| gold coins.""", MsgBoxStyle.Information, _
                "Parameter usage.")

                Dim onBuyMessage As String = InputBox("Enter a message that the NPC will reply with when the player successfully buys an item.", "Enter Text")
                RichTextBox1.Text = Replace(RichTextBox1.Text, "</parameters>", "<parameter key=""MESSAGE_ONBUY"" value=""" & _
                            onBuyMessage & """/>" & vbNewLine & "</parameters>")
                Label11.Text = "MESSAGE_ONBUY added successfully."

            ElseIf ComboBox1.Text = "MESSAGE_ONSELL" Then
                MsgBox("Examples of this parameter:" & vbNewLine & _
                       """Thank you for selling |ITEMCOUNNT| |ITEMNAME| for |TOTALCOST| gold coins.""", MsgBoxStyle.Information, _
                "Parameter usage.")

                Dim onSellMessage As String = InputBox("Enter a message that the NPC will reply with when the player successfully sells an item.", "Enter Text")
                RichTextBox1.Text = Replace(RichTextBox1.Text, "</parameters>", "<parameter key=""MESSAGE_ONSELL"" value=""" & _
                            onSellMessage & """/>" & vbNewLine & "</parameters>")
                Label11.Text = "MESSAGE_ONSELL added successfully."

            ElseIf ComboBox1.Text = "MESSAGE_NOTHAVEITEM" Then
                MsgBox("Examples of this parameter:" & vbNewLine & _
                       """Sorry,you do not have any |ITEMNAME|.""", MsgBoxStyle.Information, _
                "Parameter usage.")

                Dim notHaveItemMessage As String = InputBox("Enter a message that the NPC will reply with when the player does not have an item.", "Enter Text")
                RichTextBox1.Text = Replace(RichTextBox1.Text, "</parameters>", "<parameter key=""MESSAGE_NOTHAVEITEM"" value=""" & _
                            notHaveItemMessage & """/>" & vbNewLine & "</parameters>")
                Label11.Text = "MESSAGE_NOTHAVEITEM added successfully."

            ElseIf ComboBox1.Text = "MESSAGE_IDLETIMEOUT" Then
                MsgBox("Examples of this parameter:" & vbNewLine & _
                       """Good bye, |PLAYERNAME|."" or" & vbNewLine & """Next please!""", MsgBoxStyle.Information, _
                "Parameter usage.")

                Dim idleTimeOutMessage As String = InputBox("Enter a message that the NPC will reply with when the player does not speak with the NPC for 30 seconds.", "Enter Text")
                RichTextBox1.Text = Replace(RichTextBox1.Text, "</parameters>", "<parameter key=""MESSAGE_IDLETIMEOUT"" value=""" & _
                            idleTimeOutMessage & """/>" & vbNewLine & "</parameters>")
                Label11.Text = "MESSAGE_IDLETIMEOUT added successfully."

            ElseIf ComboBox1.Text = "MESSAGE_WALKAWAY" Then
                MsgBox("Examples of this parameter:" & vbNewLine & _
                       """Good bye, |PLAYERNAME|."" or" & vbNewLine & """How rude!""", MsgBoxStyle.Information, _
                "Parameter usage.")

                Dim walkAwayMessage As String = InputBox("Enter a message that the NPC will reply with when the player walks far away from the NPC.", "Enter Text")
                RichTextBox1.Text = Replace(RichTextBox1.Text, "</parameters>", "<parameter key=""MESSAGE_WALKAWAY"" value=""" & _
                            walkAwayMessage & """/>" & vbNewLine & "</parameters>")
                Label11.Text = "MESSAGE_WALKAWAY added successfully."

            ElseIf ComboBox1.Text = "MESSAGE_ALREADYFOCUSED" Then
                MsgBox("Examples of this parameter:" & vbNewLine & _
                       """I am already talking with you, |PLAYERNAME|.""", MsgBoxStyle.Information, _
                "Parameter usage.")

                Dim alreadyFocusedMessage As String = InputBox("Enter a message that the NPC will reply with when the player says ""hi"" to the NPC while the NPC already talks to that player.", "Enter Text")
                RichTextBox1.Text = Replace(RichTextBox1.Text, "</parameters>", "<parameter key=""MESSAGE_ALREADYFOCUSED"" value=""" & _
                            alreadyFocusedMessage & """/>" & vbNewLine & "</parameters>")
                Label11.Text = "MESSAGE_ALREADYFOCUSED added successfully."

            ElseIf ComboBox1.Text = "MESSAGE_PLACEDINQUEUE" Then
                MsgBox("Examples of this parameter:" & vbNewLine & _
                       """Please wait, |PLAYERNAME|.There are |QUEUESIZE| customers before you.""", MsgBoxStyle.Information, _
                "Parameter usage.")

                Dim queueMessage As String = InputBox("Enter a message that the NPC will reply with when the player says ""hi"" while other players said ""hi"" before that player.", "Enter Text")
                RichTextBox1.Text = Replace(RichTextBox1.Text, "</parameters>", "<parameter key=""MESSAGE_PLACEDINQUEUE"" value=""" & _
                            queueMessage & """/>" & vbNewLine & "</parameters>")
                Label11.Text = "MESSAGE_PLACEDINQUEUE added successfully."

            ElseIf ComboBox1.Text = "MESSAGE_DECLINE" Then
                MsgBox("Examples of this parameter:" & vbNewLine & _
                       """Is |TOTALCOST| for |ITEMCOUNT| |ITEMNAME| too much for you?.""", MsgBoxStyle.Information, _
                "Parameter usage.")

                Dim declineMessage As String = InputBox("Enter a message that the NPC will reply with when the player says ""no"" to the NPC for a trade offer.", "Enter Text")
                RichTextBox1.Text = Replace(RichTextBox1.Text, "</parameters>", "<parameter key=""MESSAGE_DECLINE"" value=""" & _
                            declineMessage & """/>" & vbNewLine & "</parameters>")
                Label11.Text = "MESSAGE_DECLINE added successfully."

            End If
        Else
            MsgBox("NPC Attributes and Look options must have been added before proceeding with parameters.", _
              MsgBoxStyle.Critical, "Failure!")
            Label11.Text = "Illegal Action."
        End If

    End Sub

    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
startup:
        Dim textToAdd As String = InputBox("Enter the name of the item to sell,the ID and the price,separated by commas." & vbNewLine & _
                                           "Separate different buyable items with semi-colons." & vbNewLine & _
                                          "Example: item1,1234,50; item2,5678,100", "Enter Buyable Items")

        If textToAdd.EndsWith(";") Then
            MsgBox("The last buyable item should not end with "";""", MsgBoxStyle.Critical, "Failure!")
            Label11.Text = "Illegal Action."
            GoTo startup
        Else
            RichTextBox1.Text = Replace(RichTextBox1.Text, "</parameters>", "<parameter key=""shop_buyable"" value=""" & _
                                        textToAdd & """/>" & vbNewLine & "</parameters>")
            Label11.Text = "Buyable item(s) added successfully."

        End If
    End Sub
    Private Sub CloseProgramToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseProgramToolStripMenuItem.Click
        Me.Close()
    End Sub

    Private Sub UndoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UndoToolStripMenuItem.Click
        RichTextBox1.Undo()
    End Sub

    Private Sub RedoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RedoToolStripMenuItem.Click
        RichTextBox1.Redo()
    End Sub

    Private Sub FindToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FindToolStripMenuItem.Click
        Form4.ShowDialog()
    End Sub

    Private Sub ReadMEToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReadMEToolStripMenuItem.Click
        Form2.ShowDialog()
    End Sub

    Private Sub ClearTextToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearTextToolStripMenuItem.Click
        If MessageBox.Show("Would you like to clear the current text?", "Confirmation", _
                   MessageBoxButtons.YesNo, _
                 MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
            If Label11.Text <> "" Or Label11.Text = "" Then
                Label11.Text = "Cleared Text."
                RichTextBox1.Text = "<?xml version=""1.0"" encoding=""UTF-8""?>" & _
                vbNewLine & "<!-- Created using Nikolas' NPC XML File creating software-->"
                addedLooks = False
                attributesAdded = False
            End If
        Else
            Label11.Text = "Canceled clearing."
        End If
    End Sub

    Private Sub FindReplaceToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FindReplaceToolStripMenuItem.Click
        Form3.ShowDialog()
    End Sub

    Private Sub LinkLabel1_LinkClicked_1(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
        System.Diagnostics.Process.Start("http://otland.net/forum.php")

    End Sub
End Class
